using System;
using System.Collections.Generic;

namespace SpellCore.Tests
{
    public class MockProvider : ISpellCheckEngine
    {
        private CheckingResult _expectedStatus = CheckingResult.Unknown;
        private IEnumerable<SimilarityCheckResult> _expectedSuggestions = new List<SimilarityCheckResult>();
        private bool _expectedCanSupportAdditions = false;
        private bool _expectedCanProvideSuggestions = false;

        private string _lastAddedWord;

        public CheckingResult ExpectedStatus
        {
            get { return _expectedStatus; }
            set { _expectedStatus = value; }
        }

        public IEnumerable<SimilarityCheckResult> ExpectedSuggestions
        {
            get { return _expectedSuggestions; }
            set { _expectedSuggestions = value; }
        }

        public bool ExpectedCanSupportAdditions
        {
            get { return _expectedCanSupportAdditions; }
            set { _expectedCanSupportAdditions = value; }
        }

        public string LastAddedWord
        {
            get
            {
                string s = _lastAddedWord;
                _lastAddedWord = null;
                return s;
            }
        }

        public bool ExpectedCanProvideSuggestions
        {
            get { return _expectedCanProvideSuggestions; }
            set { _expectedCanProvideSuggestions = value; }
        }

        public CheckingResult GetWordStatus(string word)
        {
            return _expectedStatus;
        }

        public bool CanSupportAdditions()
        {
            return ExpectedCanSupportAdditions;
        }

        public void AddWordAsGood(string word)
        {
            if (!CanSupportAdditions())
            {
                throw new NotSupportedException();
            }
            _lastAddedWord = word;
        }

        public bool CanSupportBadWords()
        {
            return false;
        }

        #region ISpellCheckEngine Members

        /// <summary>
        /// Adds a word to the known bad word store
        /// </summary>
        /// <param name="word"></param>
        /// <exception cref="NotSupportedException">When CanSupportBadWords is false</exception>
        public void AddWordAsBad(string word)
        {
            throw new NotImplementedException();
        }

        #endregion

        public bool CanProvideSuggestions()
        {
            return ExpectedCanProvideSuggestions;
        }

        #region ISuggestionProvider Members

        public IEnumerable<SimilarityCheckResult> GetSuggestions(string word)
        {
            if (!CanProvideSuggestions())
            {
                throw new NotSupportedException();
            }
            return ExpectedSuggestions;
        }

        #endregion

        ~MockProvider()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
        }

        private bool _isDisposed;

        private void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }
            _isDisposed = true;
            if (disposing)
            {
                //release managed resources
            }
            //release unmanaged resources
        }
    }
}